import Vue from 'vue'
import App from './App'
import router from './router'
import api from './http'
import store from './store'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import 'font-awesome/css/font-awesome.min.css'
import hljs from 'highlight.js'
import 'highlight.js/styles/monokai-sublime.css'
import '@/assets/css/index.scss'

Vue.use(ElementUI)
Vue.use(api)

// 权限判断使用$_has处理
Vue.prototype.$_has = function (perms) {
  let permissions = this.$store.state.app.perms
  for (let i = 0, len = permissions.length; i < len; i++) {
    if (permissions[i] === perms) {
      return true
    }
  }
  return false
}

Vue.directive('highlight', function (el) {
  let highlight = el.querySelectorAll('pre code')
  highlight.forEach((block) => {
    hljs.highlightBlock(block)
  })
})

// 取得当前父路径
Vue.prototype.getCurrentParentPath = function () {
  let path = this.$route.path
  return path.substr(0, path.lastIndexOf('/'))
}

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
